<?php
	include_once 'system/config/main.php';
	class db{
		// mysql commands
		public static function dbConnect(){
			// overrides
			
			$dbhost = systemConfig::$dbhost;	 // database host
			$dbname = systemConfig::$dbname; 	//database name
			$dbuser = systemConfig::$dbuser; 	// database user
			$dbpassword = systemConfig::$dbpassword; // database password
			$con = mysql_connect($dbhost,$dbuser,$dbpassword);
			if($con){
				$con_db = mysql_select_db($dbname);
				return $con;
			}else{
				return null;
			}
		}
		public static function mysqlQuery($statement){
			$con = db::dbConnect();
			return mysql_query($statement);
		}
		public static function toArray($rset){
			$data = array();
			while($row = mysql_fetch_array($rset)){
				$data[] = $row;
			}
			return $data;
		}
		public static function add($value,$table){
			$end_key = end(array_keys($value));
			$insert_data = '';
			$insert_data .= 'insert into '.$table.' ( ';
			foreach($value as $key=>$val){
				if($key==$end_key){
					$insert_data .= $key;
				}else{
					$insert_data .= $key.',';
				}
			}
			$insert_data .= ' ) VALUES ( ';
			foreach($value as $key=>$val){
				if($key==$end_key){
					$insert_data .= "'".$val."'";
				}else{
					$insert_data .= "'".$val."',";
				}
			}
			$insert_data.=');';
			db::mysqlQuery($insert_data);
		}
	}